package com.example.leetdemo.finash;

import java.util.Stack;

public class Solution155 {

    public static class MinStack {

        Stack<Integer[]> stack;

        public MinStack() {
            stack = new Stack<>();
        }

        public void push(int val) {
            Integer[] va = new Integer[2];
            va[0] = val;
            if (stack.size() > 0) {
                Integer[] latest = stack.peek();
                va[1] = Math.min(val, latest[1]);
            } else {
                va[1] = val;
            }
            stack.push(va);
        }

        public void pop() {
            stack.pop();
        }

        public int top() {
            return stack.peek()[0];
        }

        public int getMin() {
            return stack.peek()[1];
        }
    }

}
